package com.aster.service.manage.service.impl;

import com.aster.common.base.BaseServiceImpl;
import com.aster.common.dto.UserToken;
import com.aster.common.exception.ServiceException;
import com.aster.common.utils.PageUtils;
import com.aster.service.manage.dao.EscortUserLabelInfoDao;
import com.aster.service.manage.domain.TbEscortUserLabelInfo;
import com.aster.service.manage.domain.TbHospitalInfo;
import com.aster.service.manage.dto.DtoEscortUserLabelInfo;
import com.aster.service.manage.dto.DtoHospitalInfo;
import com.aster.service.manage.dto.do2dto.EscortUserLabelInfoConvert;
import com.aster.service.manage.dto.do2dto.HospitalInfoConvert;
import com.aster.service.manage.service.EscortUserLabelInfoService;
import com.aster.service.manage.service.criteria.EscortUserInfoCriteria;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * 
 * <br>
 * <b>功能：</b>TbEscortUserLabelInfoService<br>
 */
@Service("escortUserLabelInfoService")
public class  EscortUserLabelInfoServiceImpl  extends BaseServiceImpl implements EscortUserLabelInfoService {
  private final static Logger log= Logger.getLogger(EscortUserLabelInfoServiceImpl.class);
	

	@Autowired
    private EscortUserLabelInfoDao dao;

		
	public EscortUserLabelInfoDao getDao() {
		return dao;
	}


	@Override
	public PageUtils getEscortUserLabelInfoForPage(EscortUserInfoCriteria criteria) {
		Integer count = dao.queryByCount(criteria);
		if(count == null || count == 0){
			return new PageUtils(null,0);
		}
		List<TbEscortUserLabelInfo> list = dao.queryByList(criteria);
		List<DtoEscortUserLabelInfo> dtoList = EscortUserLabelInfoConvert.MAPPER.dos2dtos(list);
		return new PageUtils(dtoList,count);
	}

	@Override
	public void addEscortUserLabelInfo(TbEscortUserLabelInfo tbEscortUserLabelInfo, UserToken userToken) throws ServiceException {
		if (tbEscortUserLabelInfo == null){
			throw new ServiceException(10001,"参数为空");
		}
		try {
			// 所属企业ID
			int enterpriseId = userToken.getEnterpriseId();
			tbEscortUserLabelInfo.setEnterpriseId(enterpriseId);
			tbEscortUserLabelInfo.setCreateTime(new Date());
			tbEscortUserLabelInfo.setUpdateTime(new Date());
			tbEscortUserLabelInfo.setCreateUserId(Integer.parseInt(userToken.getUserId()));
			tbEscortUserLabelInfo.setUpdateUserId(Integer.parseInt(userToken.getUserId()));
			tbEscortUserLabelInfo.setState(1);
			tbEscortUserLabelInfo.setDeleted(1);
			dao.add(tbEscortUserLabelInfo);
		}catch (Exception ex){
			throw new ServiceException(10000,ex.getMessage());
		}
	}

	@Override
	public void editEscortUserLabelInfo(TbEscortUserLabelInfo tbEscortUserLabelInfo, UserToken userToken) throws ServiceException {
		if (tbEscortUserLabelInfo == null){
			throw new ServiceException(10001,"参数为空");
		}
		try{
			tbEscortUserLabelInfo.setUpdateUserId(Integer.parseInt(userToken.getUserId()));
			tbEscortUserLabelInfo.setUpdateTime(new Date());
			dao.updateBySelective(tbEscortUserLabelInfo);
		}catch (Exception ex){
			ex.printStackTrace();
			throw new ServiceException(10000,ex.getMessage());
		}
	}

	@Override
	public TbEscortUserLabelInfo selectByOne(Object id) {
			return dao.selectByOne(id);
	}

	@Override
	public void deleteByEscortUserIdAndEnterpriseId(Object object) {
		dao.deleteByEscortUserIdAndEnterpriseId(object);
	}
}
